package com.entrogy.controller;

import com.entrogy.bean.WeixinMenuEntity;
import com.entrogy.bean.WeixinTypeEntity;
import com.entrogy.service.WeixinMenuService;
import com.entrogy.utils.ApiReturnUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author xlr
 * @date 2019-8-22
 * @description 微信首页初始化操作，按类型放入redis缓存，注意要提高命中率哟
 * 德育处-----5，生活老师----3，家长---1，保安-----6，普通老师---2，访客----4
 * 6种类型的菜单类型一定要保持，如果要加其他职位的菜单，则需要修改放入缓存中的程序
 */
@Api(description = "微信首页菜单初始化")
@RestController
@RequestMapping(value = "/weixinmenu")
public class WeixinMenuController {

    private static final Logger logger = LoggerFactory.getLogger(WeixinMenuController.class);

    @Autowired
    private WeixinMenuService weixinMenuService;

    @ApiOperation(value = "新增微信首页菜单")
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public Map<String,Object> insertWeixinMenu(WeixinMenuEntity weixinMenuEntity){
        int code = weixinMenuService.insertWeixinMenu(weixinMenuEntity);
        if(code == 1){
            return ApiReturnUtil.success("新增成功","");
        }
        return ApiReturnUtil.error("网络异常");
    }

    @ApiOperation(value = "根据ID更新其菜单信息")
    @RequestMapping(value = "updatebyid",method = RequestMethod.POST)
    public Map<String,Object> updateWeixinMenuById(WeixinMenuEntity weixinMenuEntity){
        int code = weixinMenuService.updateWeixinMenuById(weixinMenuEntity);
        if(code == 1){
            return ApiReturnUtil.success("更新成功","");
        }
        return ApiReturnUtil.error("网络异常");
    }

    @ApiOperation(value = "根据ID删除微信首页菜单")
    @RequestMapping(value = "deletebyid",method = RequestMethod.DELETE)
    public Map<String,Object> deleteWeixinMenuById(int id){
        int code = weixinMenuService.deleteWeixinMenuById(id);
        if(code == 1){
            return ApiReturnUtil.success("删除成功","");
        }
        return ApiReturnUtil.error("网络异常");
    }

    @ApiOperation(value = "获取所有的微信菜单列表")
    @RequestMapping(value = "getweixins",method = RequestMethod.GET)
    public Map<String,Object> getWeixinMenus(){
        List<WeixinMenuEntity> lists = weixinMenuService.getWeixinMenus();
        return ApiReturnUtil.success("获取成功",lists);
    }

    @ApiOperation(value = "获取微信类型列表")
    @RequestMapping(value = "getweixintypes",method = RequestMethod.GET)
    public Map<String,Object> getWeixinTypeList(){
        List<WeixinTypeEntity> list = weixinMenuService.getWeixinTypeList();
        return  ApiReturnUtil.success("查询成功",list);
    }




}
